import {PersistConfig, persistReducer, persistStore} from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import {combineReducers, configureStore} from '@reduxjs/toolkit';
import root from './root';

const reducer = combineReducers({root});
// 持久化配置
const persistConfig: PersistConfig<ReturnType<typeof reducer>> = {
    key: 'root',
    storage,
    whitelist: ['root']
};
const persistedReducer = persistReducer(persistConfig, reducer);

const store = configureStore({
    reducer: persistedReducer,
    middleware: getDefaultMiddleware => getDefaultMiddleware({serializableCheck: false})
});


export const persistor = persistStore(store);
export type RootState = ReturnType<typeof store.getState>
export default store;

